package com.company.admin.controller.file;

import com.company.admin.common.annotations.VisitAble;
import com.company.admin.common.result.ResultResponse;
import com.company.admin.resp.file.FileUploadResponse;
import com.company.admin.service.file.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.xml.transform.Result;

/**
 * @author 赵成林
 * @date 2019/2/16 22:34
 * type : people,news
 */
@RequestMapping("/file")
@Controller
public class FileController {

    @Autowired
    private FileService fileService;


    /**
     * 为了方便验证，就暂时不用登陆也可以上传文件
     * @param multipartFiles
     * @param request
     * @param type
     * @return
     */
    @VisitAble
    @RequestMapping("/upload")
    @ResponseBody
    public ResultResponse<FileUploadResponse> upload(@RequestParam(required = false, value = "files") MultipartFile[] multipartFiles, HttpServletRequest request,@RequestParam(value = "type") String type) {
        FileUploadResponse response = fileService.upload(multipartFiles, request,type);
        return ResultResponse.onSuccess(response,null);
    }
}
